<extend name="Public/base" />
<block name="body">
    <!--PageContent-->
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Tables</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <div class="row">
           <div class="col-md-12">
    <!--formBlock-->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        Basic Form Elements
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">

                        <div class="row">
                            <div class="col-lg-8">
                                <form action="" method="post" accept-charset="utf-8" role="form">
                                    <!--textInput-->
                                    <div class="form-group">
                                        <label>链接</label>
                                        <input class="form-control" name="url" value="{$row['url']||default=''}" placeholder="Enter text">
                                    </div>
                                    <!--textInput-->
                                    <div class="form-group">
                                        <label>标题</label>
                                        <input class="form-control" name="title" value="{$row['title']||default=''}" placeholder="Enter text">
                                    </div>
                                 

                    <div class="form-group">
                        当前照片: (点击选择文件修改照片)
                        <br/>
                        <if condition=" isset($row['pic']) AND !empty($row.pic) ">
                            <img src="__ROOT__{$row['pic']|default=''}">
                        </if>
                    </div>
                <div>
                    <div>
                    <input type="file"  id="upload">
                    <input type="hidden" name="pic" id="uploadify-hidden" value="">
                    </div>

                    <div>
                        <div id="uploadify-imagelist"></div>
                    </div>
                </div>

                                    <div class="form-group">
                                        <label>状态</label>
                                        <label class="radio-inline">
                                            <input type="radio" name="status" value="1" <if condition=" isset($row['status']) AND ($row.status eq 1) ">checked</if> >正常显示
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="status"  value="0" <if condition=" isset($row['status']) AND ($row.status eq 0) ">checked</if> > 隐藏 
                                        </label>
                                    </div>  



                                    <input type="hidden" name="id" value="{$row.id|default=''}"/>  
                                    <!--/formBlock-divider-->


                                    <button type="submit" class="btn btn-default">Submit Button</button>
                                    <button type="reset" class="btn btn-default">Reset Button</button>
                                </form>
                            </div>
                        </div>

                    </div>
                </div>
                <!--/PageContent-divider-->
           </div> 
        </div>

    </div> 
    
</block>

<block name="script">
    <link href="__PUBLIC__/static/uploadify/uploadify.css" rel="stylesheet">
    <script src="__PUBLIC__/static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript">
        $(function(){
        $("#upload").uploadify({
            'width'         : 120,//按钮宽
            'height'        : 30,//按钮高
            'buttonText'      : '选择文件',//按钮名称
            'swf'           : '__PUBLIC__/static/uploadify/uploadify.swf',//flash地址
            //下面是后端相关
            "multi"         : false,//是否多图上传
            'auto'          : true,//是否自动上传
            'fileObjName'   : 'Filedata',
            'uploader'      : '{:U("Uploadify/upload")}',//处理上传的控制器
            'fileTypeExts'    : '*.jpg; *.png; *.gif;',
            'removeCompleted': true,//上传成功之后是否移除队列
            'removeTimeout' : 1,
            'onInit': function (){},        
            'onFallback'   : function() {
                alert('未检测到兼容版本的Flash.');
            },
            'onDialogClose': function(queueData){},
            'onUploadStart': function(){},
            'onUploadSuccess':  function(file, data, response) {
console.log(file);
console.log(data);// {"file":""}
console.log(response);//true 

                var result = $.parseJSON(data);
                //错误处理 巧妙的运用拦截手法，用拦截代替分支
                if(result.status == 0){ 
                    alert(result.info);
                    return false;
                }
                //上传成功
                    //设置隐藏域的值
                $('#uploadify-hidden').val(result.data.path);
                var id = Math.random().toString();
                id = id.replace('.','_'); //生成唯一标示 用于高级功能的识别例如 移除等
                var html = '<div id="'+id+'" style="background: F0F0F0;border: 1px solid #E0E0E0;  width: 160px; height:170px; overflow:hidden;" >';
                    html+= '<img height="160" width="160" src="__ROOT__'+result.data.path+'" />';
                    html+=  '</div>';
                $('#uploadify-imagelist').html(html);
            }
            
        });
    })
</script>
</block>